# 计算每个班级的最高分，最低分和平均分
grade_score = {}


def get_grade_score():
    with open("018.txt", "r", encoding="utf-8") as f:
        for line in f:
            line = line[:-1]
            # line = line.split(",")
            course, sno, name, score = line.split(",")
            # print(course, sno, name, score)
            if course not in grade_score:
                # 不能这么写是因为会报错，grade_score[course]的value会被默认成str类型，后面无法添加了
                # grade_score[course] = score
                grade_score[course] = []
            # grade_score[course].append(score)
            # 直接变int 下一个函数里面就不用变了
            grade_score[course].append(int(score))
    # print(grade_score)
    return grade_score


def get_eve_score(grade_score):
    for key, value in grade_score.items():
        max_score = max(value)
        min_score = min(value)
        # sum_score = 0
        # for i in value:
        #     sum_score += int(i)
        # average_score = sum_score / len(value)
        average_score = sum(value) / len(value)
        print(key, max_score, min_score, average_score)
        # print(key + ": " + str(value))


a = get_grade_score()
b = get_eve_score(a)
